package top.caoayu.tools.db;

import cn.smallbun.screw.core.Configuration;
import cn.smallbun.screw.core.engine.EngineConfig;
import cn.smallbun.screw.core.engine.EngineFileType;
import cn.smallbun.screw.core.engine.EngineTemplateType;
import cn.smallbun.screw.core.execute.DocumentationExecute;
import cn.smallbun.screw.core.process.ProcessConfig;
import com.zaxxer.hikari.HikariConfig;
import com.zaxxer.hikari.HikariDataSource;
import org.springframework.context.annotation.PropertySource;

import javax.sql.DataSource;
import java.util.ArrayList;

public class MysqlDocumentGeneration {
    private static final EngineFileType fileType = EngineFileType.HTML;
    private static final String outputDir = "./doc";

    public static void main(String[] args) {
        HikariConfig hikariConfig = new HikariConfig();
        hikariConfig.setDriverClassName("com.mysql.jdbc.Driver");
        hikariConfig.setJdbcUrl("jdbc:mysql://ssh.caoayu.top:3306/experience?useUnicode=true&characterEncoding=utf-8&useSSL=false");
        hikariConfig.setUsername("root");
        hikariConfig.setPassword("caoayumysql");
        //设置可以获取tables remarks信息
        hikariConfig.addDataSourceProperty("experience", "true");
        hikariConfig.setMinimumIdle(2);
        hikariConfig.setMaximumPoolSize(5);
        DataSource dataSource = new HikariDataSource(hikariConfig);

        EngineConfig engineConfig = EngineConfig.builder()
                .fileOutputDir(outputDir)
                .openOutputDir(false)
                .fileType(fileType)
                .produceType(EngineTemplateType.freemarker)
                .fileName("mysql")
                .build();
        ProcessConfig processConfig = ProcessConfig.builder()
                .designatedTableName(new ArrayList<>())
                .designatedTablePrefix(new ArrayList<>())
                .designatedTableSuffix(new ArrayList<>())
                .ignoreTableName(new ArrayList<>())
                .ignoreTablePrefix(new ArrayList<>())
                .ignoreTableSuffix(new ArrayList<>())
                .build();
        Configuration config = Configuration.builder()
                .version("1.0")
                .description("mysql")
                .dataSource(dataSource)
                .engineConfig(engineConfig)
                .produceConfig(processConfig)
                .build();
        new DocumentationExecute(config).execute();

    }
}
